import React, { Fragment, PureComponent } from 'react'
import { connect } from 'dva'
import { OssUpload } from 'scd'
// import { getParentNode } from '@/utils/getParentNode';
import { Form, Input, Spin, Select } from 'antd'
const FormItem = Form.Item;
const Option = Select.Option;

@connect(({ loading, dispatch, orgInsider, app }) => ({
  app: app,
  orgInsider: orgInsider,
  searchloading: loading.effects['orgInsider/searchOrganizaInsider']
}))
@Form.create()

class ChgOrgModalForm extends PureComponent {

  departmentList = () => {
    let dataList = []
    const { orgInsider: { orgDepartmentList } } = this.props
    const generateList = (data) => {
      for (let i = 0; i < data.length; i++) {
        const node = data[i];
        if (node.children) {
          dataList.push(node);
        }
        if (node && node.children && node.children.length !== 0) {
          generateList(node.children);
        }
      }
    };
    generateList(orgDepartmentList)
    return dataList
  }

  render() {
    const { form, modalType, dataSource, orgInsider: { orgDepartmentList }, app: { singleOriginal, organizaTreeList }, searchloading } = this.props
    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 18 },
      },
    };
    const departlist = this.departmentList()
    return (
      <Fragment>
        <Spin
          size="small"
          spinning={!!searchloading}
          tip="加载中...">
          <Form layout="horizontal">
            <FormItem {...formItemLayout} label="当前部门">
              <p>{dataSource.pathName || "暂无所属部门"}</p>
            </FormItem>
            <FormItem {...formItemLayout} label="新部门" >
              {form.getFieldDecorator('newDeptId', {
                // initialValue: null,
                rules: [{ required: true, message: '请选择要更换的部门' },
                {
                  // validator: this.validateToNextPassword
                }],
              })(<Select placeholder="请选部门">
                {departlist && departlist.map(item => {
                  return (<Option key={item.id} value={`${item.id}`}>
                    {item.name}
                  </Option>)
                })}
              </Select>)}
            </FormItem>
          </Form>
        </Spin>
      </Fragment>
    );
  }
}

export default ChgOrgModalForm;









